package com.shuyun.api.provider.controller;

import cn.hutool.core.date.DateUtil;
import com.shuyun.api.provider.bean.Member;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: shuai.chen@shuyun.com
 * @date: 2021/12/11 11:27 上午
 */
@RestController
@RequestMapping("api/members")
public class MemberController {

    @GetMapping
    public Object list() {
        List<Member> list = new ArrayList<>();
        list.add(new Member().setId(1L).setName("tom").setGender(1).setBirthday(DateUtil.parseDate("2002-12-01")));
        list.add(new Member().setId(2L).setName("merry").setGender(2).setBirthday(DateUtil.parseDate("2002-12-01")));
        return list;
    }

    @GetMapping("{id}")
    public Object detail(@PathVariable("id") Long id) {
        Member member = new Member().setId(id).setName("tom").setGender(1).setBirthday(DateUtil.parseDate("2002-12-01"));
        return member;
    }

    @PostMapping
    public Object add(@RequestBody Member member) {
        return member;
    }

    @PutMapping("{id}")
    public Object update(@PathVariable("id") Long id, @RequestBody Member member) {
        return member;
    }

    @DeleteMapping("{id}")
    public Object delete(@PathVariable("id") Long id) {
        return "删除成功";
    }

}
